const moment = require("moment");

module.exports = function(sequelize, DataTypes) {
    var LoginLog = sequelize.define('AdminLoginLog', {
        id: {
            type: DataTypes.BIGINT(20),
            allowNull: false,
            autoIncrement: true,
            primaryKey: true
        },
        user_id: {
            type: DataTypes.BIGINT(20),
            allowNull: false,
        },
        user_name: {
            type: DataTypes.STRING(64),
            allowNull: false,
        },
        name: {
            type: DataTypes.STRING(64),
            allowNull: false,
        },
        ip: {
            type: DataTypes.STRING(64),
            allowNull: false,
        },
        locations: {
            type: DataTypes.STRING(64),
        },
        login_time: {
            type: DataTypes.DATE,
            allowNull: false,
            defaultValue: new Date(),
            get() {
                return moment(this.getDataValue('login_time')).format('YYYY-MM-DD HH:mm:ss');
            }
        }
    },{
        timestamps: false,
        freezeTableName: true,
        tableName: 'system_login_log',
    });

    LoginLog.schema("public");

    // 同步模型到数据库
    LoginLog.sync({force: false}).then(function () {

    });

    return LoginLog;
};